﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace INSTA.Concepts.TemplateMethodPattern
{
    /// <summary>
    /// Abstract base class for all Files.
    /// This class implements the design pattern "Template Method.
    /// </summary>
    public abstract class AbstractFile
    {

        protected Person _person;
        protected string _fileName;

        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="person">The person.</param>
        /// <param name="fileName">Name of the file.</param>
        public AbstractFile(Person person, string fileName)
        {
            _person     = person;
            _fileName   = fileName;
        }


        /// <summary>
        /// Writes this the data of the <see cref="Person"/>
        /// This method is the "Template Method".
        /// </summary>
        public void Write()
        {
            // On appelle successivement chacune des étapes 
            // de l'algorithme.
            WriteHeader();
            WriteData();
            WriteFooter();
        }

        /// <summary>
        /// Writes the File's header.
        /// </summary>
        public abstract void WriteHeader();

        /// <summary>
        /// Writes the File's data.
        /// </summary>
        public abstract void WriteData();

        /// <summary>
        /// Writes the File's footer.
        /// </summary>
        public abstract void WriteFooter();


        /// <summary>
        /// Gets the standard bindings.
        /// </summary>
        /// <returns>the standard bindings.</returns>
        protected BindingFlags GetStandardBindings()
        {
            var flags = BindingFlags.Public     |
                        BindingFlags.NonPublic  |
                        BindingFlags.Static     |
                        BindingFlags.Instance;

            return flags;
        }

    }
}
